import os
import re
import urllib2
from BeautifulSoup import BeautifulSoup as BS
from BeautifulSoup import BeautifulStoneSoup as BSS
from ConfigParser import ConfigParser

config = ConfigParser()
config.read([os.path.expanduser('earlbot.cfg')])

def main(self, sender, channel, flags, message, DB, DEBUG, PUB_PRV):

    if channel == "NULL":
        if message.startswith("dig"):
            message = re.sub(".*define", '', message).strip()
            domain = message
            
            try:
                dig = os.popen("dig %s" %(domain)).readlines()
                if dig:
                    dig = ''.join(dig)
                    dig = re.sub("\t", " ", dig)
                    dig = re.sub("\n$", "", dig)
                    self.send_private_message(sender, "%s" %(dig))
                else:
                    self.send_private_message(sender, "I can't dig it you dig? Maybe try with fewer options.")
            except:
                self.send_private_message(sender, "I can't dig it you dig? Maybe try with fewer options.")
    
    